<template>
  <div v-if="tech" class="tech-detail">
    <!-- Header -->
    <div class="detail-header" :style="{ background: tech.gradient }">
      <div class="container">
        <router-link to="/" class="back-button">
          ← 返回首页
        </router-link>
        
        <div class="header-content">
          <div class="tech-icon-large">{{ tech.icon }}</div>
          <h1 class="tech-title">{{ tech.title }}</h1>
          <p class="tech-subtitle">{{ tech.shortDesc }}</p>
        </div>
      </div>
    </div>

    <!-- Content -->
    <div class="container">
      <div class="content-grid">
        <!-- Main Content -->
        <div class="main-content">
          <section class="content-section">
            <h2>技术概述</h2>
            <p class="description-text">{{ tech.description }}</p>
          </section>

          <!-- Architecture Visualization -->
          <section v-if="tech.architectureModules" class="content-section architecture-section">
            <h2>🏗️ 架构模块图解</h2>
            <p class="architecture-intro">以下是该技术的核心架构模块，帮助您直观理解其工作原理：</p>
            
            <div class="architecture-flow">
              <div 
                v-for="(module, index) in tech.architectureModules" 
                :key="index" 
                class="module-card"
                :style="{ animationDelay: `${index * 0.1}s` }"
              >
                <div class="module-icon">{{ module.icon }}</div>
                <div class="module-content">
                  <h4 class="module-name">{{ module.name }}</h4>
                  <p class="module-desc">{{ module.desc }}</p>
                </div>
                <div v-if="index < tech.architectureModules.length - 1" class="flow-arrow">
                  ↓
                </div>
              </div>
            </div>
          </section>

          <section class="content-section">
            <h2>核心特性</h2>
            <ul class="feature-list">
              <li v-for="(feature, index) in tech.features" :key="index" class="feature-item">
                <span class="feature-icon">✓</span>
                {{ feature }}
              </li>
            </ul>
          </section>

          <section class="content-section">
            <h2>实际应用</h2>
            <div class="application-grid">
              <div v-for="(app, index) in tech.applications" :key="index" class="application-card">
                <div class="app-number">{{ index + 1 }}</div>
                <p>{{ app }}</p>
              </div>
            </div>
          </section>

          <section class="content-section">
            <h2>发展趋势</h2>
            <div class="trends">
              <div v-for="(trend, index) in tech.trends" :key="index" class="trend-item">
                <div class="trend-icon">🔮</div>
                <p>{{ trend }}</p>
              </div>
            </div>
          </section>

          <!-- 领域导航 -->
          <section class="content-section navigation-section">
            <h2>探索其他领域</h2>
            <div class="navigation-controls">
              <router-link 
                v-if="previousTech" 
                :to="`/tech/${previousTech.id}`"
                class="nav-button prev-button"
              >
                <div class="nav-direction">← 上一个领域</div>
                <div class="nav-content">
                  <span class="nav-icon">{{ previousTech.icon }}</span>
                  <span class="nav-title">{{ previousTech.title }}</span>
                </div>
                <div class="nav-desc">{{ previousTech.shortDesc }}</div>
              </router-link>

              <div v-else class="nav-button disabled">
                <div class="nav-direction">← 已是第一个</div>
              </div>

              <router-link 
                v-if="nextTech" 
                :to="`/tech/${nextTech.id}`"
                class="nav-button next-button"
              >
                <div class="nav-direction">下一个领域 →</div>
                <div class="nav-content">
                  <span class="nav-icon">{{ nextTech.icon }}</span>
                  <span class="nav-title">{{ nextTech.title }}</span>
                </div>
                <div class="nav-desc">{{ nextTech.shortDesc }}</div>
              </router-link>

              <div v-else class="nav-button disabled">
                <div class="nav-direction">已是最后一个 →</div>
              </div>
            </div>

            <!-- 进度指示器 -->
            <div class="progress-indicator">
              <div class="progress-text">
                领域 {{ currentIndex + 1 }} / {{ technologies.length }}
              </div>
              <div class="progress-bar">
                <div 
                  class="progress-fill" 
                  :style="{ width: `${((currentIndex + 1) / technologies.length) * 100}%` }"
                ></div>
              </div>
            </div>
          </section>
        </div>

        <!-- Sidebar -->
        <aside class="sidebar">
          <div class="sidebar-card">
            <h3>相关技术</h3>
            <div class="tech-tags-detail">
              <span v-for="tag in tech.technologies" :key="tag" class="tech-tag">
                {{ tag }}
              </span>
            </div>
          </div>

          <!-- 快速导航 -->
          <div v-if="previousTech || nextTech" class="sidebar-card quick-nav">
            <h3>快速导航</h3>
            <router-link 
              v-if="previousTech" 
              :to="`/tech/${previousTech.id}`"
              class="quick-nav-link prev"
            >
              <span class="quick-nav-arrow">←</span>
              <div class="quick-nav-content">
                <span class="quick-nav-icon">{{ previousTech.icon }}</span>
                <span class="quick-nav-title">{{ previousTech.title }}</span>
              </div>
            </router-link>

            <router-link 
              v-if="nextTech" 
              :to="`/tech/${nextTech.id}`"
              class="quick-nav-link next"
            >
              <div class="quick-nav-content">
                <span class="quick-nav-icon">{{ nextTech.icon }}</span>
                <span class="quick-nav-title">{{ nextTech.title }}</span>
              </div>
              <span class="quick-nav-arrow">→</span>
            </router-link>
          </div>
        </aside>
      </div>
    </div>
  </div>

  <div v-else class="not-found">
    <div class="container">
      <h1>技术领域未找到</h1>
      <p>抱歉，您访问的技术领域不存在</p>
      <router-link to="/" class="back-home-button">返回首页</router-link>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { technologies, getTechnologyById } from '../data/technologies.js'

const route = useRoute()
const tech = computed(() => getTechnologyById(route.params.id))

// 获取当前技术的索引
const currentIndex = computed(() => 
  technologies.findIndex(t => t.id === route.params.id)
)

// 获取上一个技术
const previousTech = computed(() => {
  if (currentIndex.value <= 0) return null
  return technologies[currentIndex.value - 1]
})

// 获取下一个技术
const nextTech = computed(() => {
  if (currentIndex.value >= technologies.length - 1) return null
  return technologies[currentIndex.value + 1]
})
</script>

<style scoped>
.tech-detail {
  animation: fadeInUp 0.6s ease-out;
}

.detail-header {
  position: relative;
  padding: 4rem 0 6rem;
  margin-bottom: -3rem;
}

.detail-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, transparent 0%, var(--dark-bg) 100%);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  position: relative;
  z-index: 1;
}

.back-button {
  display: inline-flex;
  align-items: center;
  color: white;
  padding: 0.75rem 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 50px;
  font-weight: 500;
  transition: all 0.3s ease;
  margin-bottom: 2rem;
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateX(-5px);
}

.header-content {
  text-align: center;
  color: white;
}

.tech-icon-large {
  font-size: 6rem;
  margin-bottom: 1rem;
  animation: float 3s ease-in-out infinite;
}

.tech-title {
  font-size: 3.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.tech-subtitle {
  font-size: 1.5rem;
  opacity: 0.9;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 3rem;
  margin-top: 3rem;
  margin-bottom: 4rem;
}

.main-content {
  min-width: 0;
}

.content-section {
  background: var(--dark-surface);
  border: 1px solid var(--dark-border);
  border-radius: 16px;
  padding: 2.5rem;
  margin-bottom: 2rem;
}

.content-section h2 {
  color: var(--text-primary);
  font-size: 2rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--dark-border);
}

.description-text {
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1.8;
}

.feature-list {
  list-style: none;
  display: grid;
  gap: 1rem;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
  font-size: 1.1rem;
  padding: 1rem;
  background: rgba(99, 102, 241, 0.05);
  border-radius: 8px;
  border-left: 3px solid var(--primary-color);
}

.feature-icon {
  color: var(--primary-color);
  font-weight: 700;
  font-size: 1.3rem;
}

.application-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
}

.application-card {
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 12px;
  padding: 1.5rem;
  transition: all 0.3s ease;
}

.application-card:hover {
  transform: translateY(-5px);
  border-color: var(--primary-color);
  box-shadow: 0 10px 30px rgba(99, 102, 241, 0.2);
}

.app-number {
  width: 40px;
  height: 40px;
  background: var(--gradient-1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin-bottom: 1rem;
  font-size: 1.2rem;
}

.application-card p {
  color: var(--text-secondary);
  line-height: 1.6;
}

.trends {
  display: grid;
  gap: 1.5rem;
}

.trend-item {
  display: flex;
  gap: 1.5rem;
  padding: 1.5rem;
  background: rgba(139, 92, 246, 0.05);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 12px;
  transition: all 0.3s ease;
}

.trend-item:hover {
  transform: translateX(10px);
  border-color: var(--secondary-color);
}

.trend-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.trend-item p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1.6;
}

.sidebar {
  position: sticky;
  top: 2rem;
  height: fit-content;
}

.sidebar-card {
  background: var(--dark-surface);
  border: 1px solid var(--dark-border);
  border-radius: 16px;
  padding: 2rem;
  margin-bottom: 2rem;
}

.sidebar-card h3 {
  color: var(--text-primary);
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
}

.tech-tags-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tech-tag {
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-color);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid rgba(99, 102, 241, 0.2);
  transition: all 0.3s ease;
}

.tech-tag:hover {
  background: rgba(99, 102, 241, 0.2);
  transform: scale(1.05);
}

.not-found {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.not-found h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.not-found p {
  color: var(--text-secondary);
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

.back-home-button {
  display: inline-block;
  background: var(--gradient-1);
  color: white;
  padding: 1rem 2rem;
  border-radius: 50px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.back-home-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
}

@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    position: static;
  }
}

/* Architecture Visualization */
.architecture-section {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(139, 92, 246, 0.05));
  border: 2px solid rgba(99, 102, 241, 0.3);
}

.architecture-intro {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 2rem;
  padding: 1rem;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 8px;
  border-left: 3px solid var(--neon-blue);
}

.architecture-flow {
  display: grid;
  gap: 0;
  position: relative;
}

.module-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.5rem;
  padding: 1.5rem;
  background: rgba(26, 31, 53, 0.8);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 16px;
  margin-bottom: 1rem;
  position: relative;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideInUp 0.6s ease-out backwards;
}

.module-card:hover {
  transform: translateX(10px) scale(1.02);
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--neon-blue);
  box-shadow: 
    0 10px 40px rgba(99, 102, 241, 0.3),
    0 0 20px rgba(0, 243, 255, 0.2);
}

.module-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--neon-blue), var(--neon-purple));
  border-radius: 4px 0 0 4px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.module-card:hover::before {
  opacity: 1;
}

.module-icon {
  font-size: 3rem;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
  border-radius: 16px;
  border: 2px solid rgba(99, 102, 241, 0.3);
  flex-shrink: 0;
  transition: all 0.4s ease;
}

.module-card:hover .module-icon {
  transform: rotate(360deg) scale(1.1);
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.5);
}

.module-content {
  flex: 1;
}

.module-name {
  color: var(--text-primary);
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.module-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin: 0;
  font-family: 'Courier New', monospace;
  opacity: 0.8;
}

.flow-arrow {
  position: absolute;
  left: 50%;
  bottom: -1.5rem;
  transform: translateX(-50%);
  font-size: 2rem;
  color: var(--neon-purple);
  text-shadow: 0 0 20px var(--neon-purple);
  animation: bounce 2s ease-in-out infinite;
  z-index: 10;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce {
  0%, 100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(5px);
  }
}

/* 领域导航样式 */
.navigation-section {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.08));
  border: 2px solid rgba(99, 102, 241, 0.2);
}

.navigation-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.nav-button {
  padding: 1.5rem;
  background: var(--dark-surface);
  border: 2px solid var(--dark-border);
  border-radius: 12px;
  transition: all 0.3s ease;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.nav-button:not(.disabled):hover {
  border-color: var(--primary-color);
  background: rgba(99, 102, 241, 0.1);
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(99, 102, 241, 0.2);
}

.nav-button.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.nav-direction {
  color: var(--primary-color);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.nav-icon {
  font-size: 2rem;
}

.nav-title {
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 600;
}

.nav-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
}

.progress-indicator {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--dark-border);
}

.progress-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 0.75rem;
  font-weight: 500;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--gradient-1);
  border-radius: 10px;
  transition: width 0.5s ease;
}

/* 侧边栏快速导航 */
.quick-nav h3 {
  background: var(--gradient-1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.quick-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: rgba(99, 102, 241, 0.05);
  border: 2px solid var(--dark-border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  transition: all 0.3s ease;
}

.quick-nav-link:hover {
  border-color: var(--primary-color);
  background: rgba(99, 102, 241, 0.15);
  transform: translateX(5px);
}

.quick-nav-link.prev:hover {
  transform: translateX(-5px);
}

.quick-nav-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
}

.quick-nav-icon {
  font-size: 1.5rem;
}

.quick-nav-title {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
}

.quick-nav-arrow {
  color: var(--primary-color);
  font-size: 1.5rem;
  font-weight: 700;
}

@media (max-width: 768px) {
  .tech-icon-large {
    font-size: 4rem;
  }
  
  .tech-title {
    font-size: 2.5rem;
  }
  
  .tech-subtitle {
    font-size: 1.2rem;
  }
  
  .application-grid {
    grid-template-columns: 1fr;
  }

  .module-card {
    grid-template-columns: auto 1fr;
    gap: 1rem;
  }

  .module-icon {
    width: 60px;
    height: 60px;
    font-size: 2rem;
  }

  .module-name {
    font-size: 1.1rem;
  }

  .module-desc {
    font-size: 0.85rem;
  }

  .navigation-controls {
    grid-template-columns: 1fr;
  }

  .nav-icon {
    font-size: 1.5rem;
  }

  .nav-title {
    font-size: 1rem;
  }
}
</style>

